package com.android.openapp.ui;

import com.android.openapp.R;
import com.android.openapp.data.Place;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class Utils {
	
	public static void showToast(Context context, String text) {
		Log.i("HTTP DOWNLOADER", "DOWNLOAD COMPLETED, TOAST FUNCTION");
		Toast.makeText(context, "The operation returned:\n" + text, Toast.LENGTH_LONG).show();
	}
	
	/*public static void showPlaceInfo(final Context context, int resource, final int placeListIndex) {
		Place place = Place.lista.get(placeListIndex);
		// preparo la view da visualizzare nel Dialog
		//final Context mAppContext = context.getApplicationContext();
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(resource, null);
        String title = place.getDenominazione();
        //UI elements
        TextView tipo = (TextView)layout.findViewById(R.id.tipo);
        TextView indirizzo = (TextView)layout.findViewById(R.id.indirizzo);
        tipo.setText(place.getTipologia());
        indirizzo.setText(place.getAddress());
        TextView contatti = (TextView) layout.findViewById(R.id.contatti);
        String cInfo = place.getContactInfo();
        if(cInfo != null)
        	contatti.setText(cInfo);
        
        // costruisco il Dialog
		AlertDialog.Builder builder = new AlertDialog.Builder(context);
		builder.setView(layout).setIcon(android.R.drawable.ic_dialog_info).
		setTitle(title).setCancelable(true)
			.setPositiveButton("OK", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int id) {
					}
				});
		final AlertDialog dialog = builder.create();
		dialog.show();
		
		//coordinate
		final Double lat = place.getLatitude();
		final Double lon = place.getLongitude();
		
		//bottone per passare alla mappa
        Button mapButton = (Button) layout.findViewById(android.R.id.button1);
        mapButton.setOnClickListener(new View.OnClickListener(){

			@Override
			public void onClick(View v) {
				if(lat != null && lon != null){
					
					Intent i = new Intent(MainActivity.VIEW_MAP_TAB);
					i.putExtra("latitude", lat);
					i.putExtra("longitude", lon);
					i.putExtra("index", placeListIndex);
					v.getContext().sendBroadcast(i);
					dialog.dismiss();
				}
				else {
					String text = context.getResources().getString(R.string.noaddressfound);
					Utils.showToast(context, text);
				}
			}
        	
        });
	}*/
	
}
